<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登陆</title>
</head>
<body>
    <h2>用户登陆</h2>
    <p>账号：<input type="text" id="uname"></p>
    <p>密码：<input type="password" id="upassword"></p>
    <p><input type="radio" id="IfRemember">记住密码</p>
    <p><button id="btn">登陆</button></p>


    <script><!--js的代码-->
        document.getElementById('btn').onclick = function () {

            if(document.getElementById('IfRemember').checked) {
                let uname = document.getElementById('uname').value;
                let upassword = document.getElementById("upassword").value;

                //永久存储到域上，并把对象转化为字符串的形式
                localStorage.setItem('userInfo',JSON.stringify({ uname , upassword}));
            }
        }
    //获取域中的数据
    if(localStorage.getItem('userInfo') !=null) { //空就是null

        let userInfo = JSON.parse(localStorage.getItem('userInfo'));

        document.getElementById('uname').value =userInfo.uname;
        document.getElementById('upassword').value =userInfo.upassword;
    }
    </script>
</body>
</html>




